const webpack = require("webpack")
const path = require("path")
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { HotModuleReplacementPlugin } = require('webpack')
// const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

module.exports = {
    mode: "development",
    entry: "./src/index.js",
    output: {
        filename: "[name].js",
        path: path.resolve(__dirname, "dist") 
    },
    devtool: "source-map",
    module: {
        rules: [
            {
                test: /\.js|\.jsx$/,
                use: "babel-loader",
                exclude: /node_modules/
            },
            {
                test: /.css$/, // 匹配文件
                use: [// use指定使用到的loader
                  'style-loader',
                  'css-loader'
                ]
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            template: './src/index.html',
            filename: 'index.html',
        }),
        // new HotModuleReplacementPlugin(),
        // new ReactRefreshPlugin()
    ],
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "src")
        },
        extensions: ['.js', '.jsx']
    },
    target: "web", 
    devServer: {
        host: "127.0.0.1",
        port: "9999",
        historyApiFallback: true,
        hot: true,
        // static: {
        //     directory: path.resolve(__dirname, "dist"),
        //     publicPath: path.resolve(__dirname, "dist"),
        //     watch: true
        // },
        // open: true
    }
}